package net.xdclass.xdclass.service.impl;

import net.xdclass.xdclass.config.CacheKeyManager;
import net.xdclass.xdclass.mapper.VideoBannerMapper;
import net.xdclass.xdclass.model.pojo.VideoBanner;
import net.xdclass.xdclass.service.VideoBannerService;
import net.xdclass.xdclass.utils.BaseCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ExecutionException;

@Service
public class VideoBannerServiceImpl implements VideoBannerService {

    @Autowired
    VideoBannerMapper videoBannerMapper;

    @Autowired
    BaseCache baseCache;
    @Override
    public List<VideoBanner> listVideoBanner() {

        try {
            Object cacheObj = baseCache.getTenMinuteCache().get(CacheKeyManager.INDEX_BANNER_KEY, () -> {
                List<VideoBanner> bannerList = videoBannerMapper.listVideoBanner();

                System.out.println("从数据库里面找轮播图列表");
                return bannerList;
            });
            if (cacheObj instanceof List){
                List<VideoBanner> bannerList = (List<VideoBanner>)cacheObj;
                return bannerList;
            }
        } catch (ExecutionException e) {
            e.printStackTrace();
        }


        //可以返回兜底数据，业务系统降级-》SpringCloud专题课程
        return null;
    }
}
